< previous page page_52 next page >

Page 52
Type.gifListing 3.7. Displaying the record count of the filtered Recordset.
Private Sub Form_Load()
'
    ' creating dynaset-type recordsets
    '
    Dim db As Database ' the database object
    Dim rs As Recordset ' the recordset object
    Dim rs2 As Recordset ' another recordset
    Dim rs3 As Recordset ' for cloning
    '
    ' create local variables
    Dim strDBName As String
    Dim strRSName As String
    Dim intRecs As Integer
    Dim strFilter As String
    '
    ' initialize the variables
    strDBName = App.Path & "\..\..\data\books5.mdb"
    strRSName = "Titles"
    strFilter = "YearPub>1990"
    '
    ' create the objects
    Set db = DBEngine.OpenDatabase(strDBName)
    Set rs = db.OpenRecordset(strRSName, dbOpenDynaset)
    '
    ' count the records in the collection
    rs.MoveLast ' move to end of list to force a count
    intRecs = rs.RecordCount ' get count
    MsgBox strRSName & " :" & CStr(intRecs), vbInformation, "Total Records in
Set"
    '
    ' create filtered collection
    rs.Filter = strFilter
    Set rs2 = rs.OpenRecordset
    '
    ' count the records in the collection
    rs2.MoveLast ' move to end of list to force a count
    intRecs = rs2.RecordCount ' get count
    MsgBox strFilter & " :" & CStr(intRecs), vbInformation, "Total Records in
Set"
    ' exit program
    End
    '
End Sub
Save and run the code to check the results (see Figure 3.4). Notice that the first record count (the full dataset) is larger than the second record count (the filtered dataset).

 
< previous page page_52 next page >

If you like this book, buy it!